<!DOCTYPE html>
<html  lang="en">
    <head>
        <title>Document</title>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    </head>
    <body>
        <div id="app">
            <weixiauthor></weixiauthor>
            <weixinuser></weixinuser>
        </div>

        <script>
            let bus = new Vue()             // 空的Vue实例，就是中央事件总线

            Vue.component("weixiauthor",
            {
                template:
				`<div>
                    <p>我是微信公众号作者</p>
                    <input ref="ref01">
                    <button @click="handleClick()">发送</button>
                </div>`,
                methods: {
                    handleClick(){
                        bus.$emit("weixin",this.$refs.ref01.value)
                    }
                }
            })

            Vue.component("weixinuser",
            {
                template:
				`<div>
                    <p>我是微信公众号订阅者</p>
                    <textarea ref="ref02"></textarea>
                </div>`,
                mounted(){
                    bus.$on("weixin",data => this.$refs.ref02.value = data)
                }
            })

            let vm = new Vue({
                el: '#app',
                data: {
                    msg: 'ok',
                },
            })
        </script>
    </body>
</html>